package org.example.dingtalkintegrationservice.pojo.form;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Form {
    String name;
    String description;
    public String classCode;
    public String processId;
public List<Field> fields=new ArrayList<>();
    @JsonTypeInfo(
            use = JsonTypeInfo.Id.NAME, // 使用字段名称来确定子类
            include = JsonTypeInfo.As.PROPERTY, // 字段在JSON中存储为属性
            property = "type" // 字段名称
    )
    @JsonSubTypes({
            @JsonSubTypes.Type(value = TextField.class, name = "TextField"),
            @JsonSubTypes.Type(value = TableField.class, name = "TableField")
    })
public static class Field{
    public String label;
    public String type;
}
public static class TextField extends Field{
}
public static class TableField extends Field{
    public List<TextField> children=new ArrayList<>();
}
    public  String repeated(){
        Set<String> labels=new HashSet<>();
        for (Field field:fields){
            if (labels.contains(field.label)){
                return field.label;
            }
            else {
                labels.add(field.label);
            }
        }
        return "no";
    }
}
